package com.tt.vtg.utils;

import java.security.MessageDigest;

import org.springframework.util.StringUtils;

public class VtgUtils {
	private final static int INT_0X_FF = 0xFF;
	private VtgUtils(){}
	
	private static String bytesToHex(byte[] bts){
		StringBuffer des = new StringBuffer();
        String tmp = null;
        for (int i = 0; i < bts.length; i++) {
            tmp = (Integer.toHexString(bts[i] & INT_0X_FF));
            des.append(tmp.length()==1?"0":tmp);
        }
        return des.toString();
	}
	
	private static MessageDigest md5() {  
        try {  
            return MessageDigest.getInstance("MD5");  
        } catch (Exception e) {  
            return null;  
        }  
    }
	
	public static String encrypt(String str){
		if(!StringUtils.hasText(str)){
			return "";
		}
		
		byte[] bts = str.getBytes();
		MessageDigest md = md5();
		md.update(bts);
		
		return bytesToHex(md.digest()).toUpperCase();
	}
	
	public static String generateSalt(){
		return RandomGenerator.getInstance().generate();
	}
	
	public static void main(String[] args) {
		System.out.println(encrypt("12345"+"cegikm-opq23t5uv8xz="));
	}
}
